#ifndef __LIST_H__
#define __LIST_H__

#include <stdarg.h>

#include "dtk_types.h"

typedef struct _d_link
{
    DInt                magic;
    DPointer            data;
    struct _d_link      *prev;
    struct _d_link      *next;
}DLink;

typedef struct _d_list
{
    DPointer    self;
    DInt        count;
    DLink       *data;
}DList;

typedef DInt (*DTKCompare)(DLink* link1, DLink* link2);
typedef DBoolean (*LinkCallBack)(DList* list, DLink* link, va_list args);

void dtk_list_prepend( DList *list, DLink *link );
void dtk_list_append( DList *list, DLink *link );
DInt dtk_list_get_count (DList* list);
void dtk_list_remove( DList *list, DLink *link );
DLink* dtk_list_get_next (DLink* link);
DLink* dtk_list_get_prev (DLink* link);
DLink* dtk_list_get_first (DList* list);
DBoolean dtk_list_check_link(DLink *link );
DBoolean dtk_list_foreach(DList* list, LinkCallBack cb, ...);


#define DLIST(x)    (&(x)->list)
#define DLINK(x)    (&(x)->link)
#define DLISTDATA(x) ((x)->self);
#define DLINKDATA(x) ((x)->data);
#endif
